package com.ke.rule.base;

import org.apache.commons.lang3.ClassUtils;

/**
 * 调用分解
 * 
 * @author guyu
 */
public final class CallBreakdown {

  public static final String GROUP_METHOD = "Method&Step";
  public static final String GROUP_VISITOR = "Visitor";
  public static final String GROUP_FUNC_UNIT = "DecisionTable&FuncUnit&Functor";
  
  /**
   * 获取时延分解的扩展名
   * @param visitor
   * @param entity
   * @return
   */
//  public static String getBreakdownExtension(IBaseVisitor<?> visitor, BaseEntity entity) {
//    MethodStepType stepType = null;
//    if (visitor instanceof BaseVisitorAdapter) {
//      stepType = ((BaseVisitorAdapter<?>) visitor).getContext().getCurrentStepType();
//    }
//    // 允许同一个visitor针对不同的entity执行多次
//    return getBreakdownExtension(stepType, entity);
//  }
  
  private static String getBreakdownExtension(MethodStepType stepType, Object value) {
    return String.format("%s@%s-%s", ClassUtils.getSimpleName(value),
        // value.hashCode()会被重载导致性能不可控，故使用identityHashCode
        Integer.toHexString(System.identityHashCode(value)), stepType);
  }
  
  public static String getBreakdownExtension(ServiceMethodContext context, Object value) {
    return getBreakdownExtension(context.getCurrentStepType(), value);
  }
}
